package 简单.对称二叉树;

import java.util.LinkedList;

//迭代
public class Solution2 {
    public boolean isSymmetric(TreeNode root) {
        return checkTree(root,root);
    }

    public boolean checkTree(TreeNode p , TreeNode q){
        LinkedList<TreeNode> queue = new LinkedList<>();

        queue.offer(p);
        queue.offer(q);

        while (!queue.isEmpty()){
            TreeNode x = queue.poll();
            TreeNode y = queue.poll();

            if(x == null && y== null){
                return true;
            }

            if (x == null || y == null || x.val != y.val){
                return false;
            }

            queue.offer(p.left);
            queue.offer(q.right);
            queue.offer(p.right);
            queue.offer(q.left);
        }
        return true;
    }
}
